package com.kim.user.web.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.kim.user.common.entity.SysUser;
import com.kim.user.common.entity.SysUserExample;
import com.kim.user.web.dao.SysUserMapper;
import com.kim.user.web.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Mr.Yangxiufeng
 * Date: 2018-05-10
 * Time: 19:57
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private SysUserMapper userMapper;

    @Override
    public SysUser findByUsername(String username) {
        SysUserExample sysUserExample = new SysUserExample();
        SysUserExample.Criteria criteria = sysUserExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<SysUser> sysUsers = userMapper.selectByExample(sysUserExample);
        return sysUsers == null || sysUsers.size() == 0? null :sysUsers.get(0);
    }

    @Override
    @LcnTransaction
    @Transactional
    public int insertUser(SysUser sysUser) {
        log.info("开始执行user insert方法");
        int i = userMapper.insertSelective(sysUser);
        log.info("执行成功");
        return i;
    }


}
